﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using MoroMoro.Samples.ToDoList.Base.Domain.Specifications;

namespace MoroMoro.Samples.ToDoList.Domain.Categories
{
    /// <summary>
    /// <see cref="Category">カテゴリ</see>の<see cref="Category.Name">名前</see>が特定の名前と一致するかどうかを判断します。
    /// </summary>
    [Serializable]
    public sealed class CategoryNameSpecification : Specification<Category>
    {
        /// <summary>
        /// <see cref="CategoryNameSpecification"/> クラスの新しいインスタンスを初期化します。
        /// </summary>
        /// <param name="name"><see cref="Category">カテゴリ</see>の<see cref="Category.Name">名前</see>。</param>
        public CategoryNameSpecification(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            _name = name;
        }


        /// <summary>
        /// <see cref="Category">カテゴリ</see>の<see cref="Category.Name">名前</see>。
        /// </summary>
        private readonly string _name;


        /// <inheritdoc/>
        protected override Expression<Func<Category, bool>> CreateExpression()
        {
            return entity => entity.Name == _name;
        }
    }
}
